using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using TienTeTuong;
using log4net;
namespace TienTeTuong
{
    public class CategoryDetailBUS
    {
      
         public List<CategoryDetailDTO> GetListCategoryDetailByCateID(string CateID)
         {
             var dao = new CategoryDetailDAO();
             return dao.GetListCategoryDetailByCateID(CateID);
         }
        public CategoryDetailDTO GetCategoryDetailByID(string CateDetailID)
        {
            var dao = new CategoryDetailDAO();
            return dao.GetCategoryDetailByID(CateDetailID);
        }
         public List<CategoryDetailDTO> GetHotListCategoryDetail()
         {
             var dao = new CategoryDetailDAO();
             return dao.GetHotListCategoryDetail();
         }

        public List<CategoryDetailDTO> GetListCategoryByPage(string cateID, int numPage,int numPerPage, out int iTotalPages, out int iCurPage, out int iLowerPage, out int iUpperPage, out int iTotalResult)
        {                                                              

            iCurPage = numPage;
            var dao = new CategoryDetailDAO();

            iTotalResult = dao.GetNumCategoryDetail(cateID);

            iTotalPages = iTotalResult / numPerPage + (iTotalResult % numPerPage > 0 ? 1 : 0);
            if (iCurPage < 1) iCurPage = 1;
            if (iCurPage > iTotalPages) iCurPage = iTotalPages;
            Common.CalculateBoundry(numPerPage, iTotalPages, iCurPage, out iLowerPage, out iUpperPage);
            var offsetFirstRow = (iCurPage - 1) * numPerPage;
            if (offsetFirstRow < 0) offsetFirstRow = 0;

            return dao.GetListCategoryByPage(cateID,offsetFirstRow, numPerPage);
             
        }

        public List<CategoryDetailDTO> GetHotListCategoryDetail(int Top)
        {
            var dao = new CategoryDetailDAO();
            return dao.GetHotListCategoryDetail(Top);
        }
         public List<CategoryDetailDTO> SearchListCategoryByPage(string cateID,string keyword, int numPage,int numPerPage, out int iTotalPages, out int iCurPage, out int iLowerPage, out int iUpperPage, out int iTotalResult)
         {
             iCurPage = numPage;
             var dao = new CategoryDetailDAO();

             iTotalResult = dao.SearchNumCategoryDetail(cateID,keyword);

             iTotalPages = iTotalResult / numPerPage + (iTotalResult % numPerPage > 0 ? 1 : 0);
             if (iCurPage < 1) iCurPage = 1;
             if (iCurPage > iTotalPages) iCurPage = iTotalPages;
             Common.CalculateBoundry(numPerPage, iTotalPages, iCurPage, out iLowerPage, out iUpperPage);
             var offsetFirstRow = (iCurPage - 1) * numPerPage;
             if (offsetFirstRow < 0) offsetFirstRow = 0;

             return dao.SearchListCategoryByPage(cateID,keyword, offsetFirstRow, numPerPage);
         }
         public List<CategoryDetailDTO> GetListCategoryDetail()
         { 
             var dao = new CategoryDetailDAO();
             return dao.GetListCategoryDetail(); 
         }
         public List<CategoryDetailDTO> searchCategoryDetailByName(string key)
         {
             var dao = new CategoryDetailDAO();
             return dao.searchCategoryDetailByName(key);
         }
         public bool delete(string key)
         {
             var dao = new CategoryDetailDAO();
             return dao.delete(key);
         }
         public bool update(CategoryDetailDTO item)
         {
             var dao = new CategoryDetailDAO();
             return dao.update(item);
         }

         public bool add(CategoryDetailDTO item)
         {
             var dao = new CategoryDetailDAO();
             return dao.add(item);
         }
    }
}
